package com.sfh.cpc.com.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sfh.cpc.com.R;
import com.sfh.cpc.com.entity.EMass;
import com.sfh.cpc.com.entity.EUser;

/**
 * 功能描述:
 *
 * @author SunFeihu 孙飞虎
 * @date 2019/5/20
 */
public class VIPAgeUserView extends LinearLayout {
    public VIPAgeUserView(Context context) {
        super(context);
        this.init(context);

    }

    public VIPAgeUserView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.init(context);
    }

    public VIPAgeUserView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.init(context);
    }

    ImageView vip;
    ImageView ivAge;
    ImageView ivAge2;
    TextView tv_address;

    private void init(Context context) {
        this.setGravity(Gravity.CENTER);
        inflate(context, R.layout.widget_layout_vip_user, this);
        vip = findViewById(R.id.iv_vip);
        ivAge = findViewById(R.id.iv_age);
        ivAge2 = findViewById(R.id.iv_age2);
        tv_address = findViewById(R.id.tv_address);
    }

    public void showVIP(EUser user) {
        if (user.isVip()) {
            vip.setVisibility(VISIBLE);
        } else {
            vip.setVisibility(GONE);
        }
        tv_address.setText(user.getUserAddress());
        //财力
        long userWealth = user.getUserWealth();
        //魅力
        long userCharm = user.getUserCharm();

        int age = (int) (userWealth / 100 + (userWealth % 100 > 0 ? 1 : 0))

                + (int) (userCharm / 500 + (userWealth % 500 > 0 ? 1 : 0));
        if (age > 20) {
            this.ivAge.setVisibility(GONE);
            this.ivAge2.setVisibility(VISIBLE);
            this.ivAge2.setImageResource(getImageView(age));
        } else {
            this.ivAge.setVisibility(VISIBLE);
            this.ivAge2.setVisibility(GONE);
            this.ivAge.setImageResource(getImageView(age));
        }
    }

    private int getImageView(int size) {
        switch (size) {
            case 0:
                return R.drawable.lv_1;
            case 1:
                return R.drawable.lv_1;
            case 2:
                return R.drawable.lv_2;
            case 3:
                return R.drawable.lv_3;
            case 4:
                return R.drawable.lv_4;
            case 5:
                return R.drawable.lv_5;
            case 6:
                return R.drawable.lv_6;
            case 7:
                return R.drawable.lv_7;
            case 8:
                return R.drawable.lv_8;
            case 9:
                return R.drawable.lv_9;
            case 10:
                return R.drawable.lv_10;
            case 11:
                return R.drawable.lv_11;
            case 12:
                return R.drawable.lv_12;
            case 13:
                return R.drawable.lv_13;
            case 14:
                return R.drawable.lv_14;
            case 15:
                return R.drawable.lv_15;
            case 16:
                return R.drawable.lv_16;
            case 17:
                return R.drawable.lv_17;
            case 18:
                return R.drawable.lv_18;
            case 19:
                return R.drawable.lv_19;
            case 20:
                return R.drawable.lv_20;
            case 21:
                return R.drawable.lv_21;
            case 22:
                return R.drawable.lv_22;
            case 23:
                return R.drawable.lv_23;
            case 24:
                return R.drawable.lv_24;
            case 25:
                return R.drawable.lv_25;
            case 26:
                return R.drawable.lv_26;
            case 27:
                return R.drawable.lv_27;
            case 28:
                return R.drawable.lv_28;
            case 29:
                return R.drawable.lv_29;
            case 30:
                return R.drawable.lv_30;
            case 31:
                return R.drawable.lv_31;
            case 32:
                return R.drawable.lv_32;
            case 33:
                return R.drawable.lv_33;
            case 34:
                return R.drawable.lv_34;
            case 35:
                return R.drawable.lv_35;
            case 36:
                return R.drawable.lv_36;
            case 37:
                return R.drawable.lv_37;
            case 38:
                return R.drawable.lv_38;
            case 39:
                return R.drawable.lv_39;
            case 40:
                return R.drawable.lv_40;
            default:
                return R.drawable.lv_40;
        }
    }
}
